package com.fortest;

import com.grapecity.documents.excel.Workbook;
import com.mypg.Question;
import com.mypg.TQuestion;
import com.mypg.User;
import com.service.Impl.QuestionServiceImpl;
import com.service.Impl.UserServiceImpl;
import com.service.QuestionService;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Test8 {

    private static UserService userService;
    private static QuestionService questionService;

    public static UserService getUserService(){
        if(userService==null){
            String config="applicationcontext.xml";
            ApplicationContext ac=new ClassPathXmlApplicationContext(config);
            userService=(UserServiceImpl) ac.getBean("userService");
        }
        return userService;
    }

    public static QuestionService getQuestionService(){
        if(questionService==null){
            String config="applicationcontext.xml";
            ApplicationContext ac=new ClassPathXmlApplicationContext(config);
            questionService=(QuestionServiceImpl) ac.getBean("questionService");
        }
        return questionService;
    }

    public static void main(String[] args){
//        Workbook wb=new Workbook();
//        try {
//            File file=new File("E:\\毕设有关\\题库\\excel文件\\TemplateWorkWithTable1.xlsx");
//            InputStream is=new FileInputStream("E:\\毕设有关\\题库\\excel文件\\TemplateWorkWithTable1.xlsx");
//            wb.open(is);
//            List<User> datasource=Test8.getUserService().selectAllUser();
////            User user=new User();
////            user.setUser_id(9);
////            user.setUser_name("fuck");
////            user.setPassword("123");
////            user.setUser_nickname("fuck");
////            datasource.add(user);
//            wb.addDataSource("ds",datasource);
//            wb.processTemplate();
//            wb.save("E:\\毕设有关\\题库\\excel文件\\t_test1.xlsx");

        Workbook wb=new Workbook();
        try {
            InputStream is=new FileInputStream("E:\\毕设有关\\题库\\excel文件\\TemplateWorkWithTable3.xlsx");
            wb.open(is);
            List<TQuestion> datasource=Test8.getQuestionService().selectAllTQuestion();
            wb.addDataSource("ds",datasource);
            wb.processTemplate();
            wb.save("E:\\毕设有关\\题库\\excel文件\\ke4_tiku.xlsx");




        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
